package com.itheima.controller;

import com.itheima.common.constant.MessageConstant;
import com.itheima.common.entity.Result;
import com.itheima.pojo.TelephoneCode;
import com.itheima.service.MemberService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.http.server.DelegatingServerHttpResponse;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/member")
@Slf4j
@Api(tags = "")
public class MemberController {


    @Autowired
    private MemberService memberService;

    /**
     * 手机验证码登录
     * @param telephoneCode
     * @return
     */
    @PostMapping("/login")
    @ApiOperation("手机验证码登录")
    public Result loginByValidateCode(@RequestBody TelephoneCode telephoneCode){
        log.info("手机验证码登录:{}",telephoneCode);
        String telephone = telephoneCode.getTelephone();
        String validateCode = telephoneCode.getValidateCode();
        boolean flag = memberService.loginByValidateCode(telephone,validateCode);
        //能登陆
        if(flag){
            return new Result(true,MessageConstant.LOGIN_SUCCESS,null);
        }
        else
        return new Result(false, MessageConstant.VALIDATECODE_ERROR,null);
    }
}
